﻿//添加
var fnCustomAdd = function () {
    //    document.getElementById("dialog1_h").innerHTML = "添加客户信息";
    //    document.getElementById("EditUIWindow").src = "AutoLoadForm.aspx?r=" + Math.random() + "&entity=Cst_customer";
    //    SetMaxDWH(YAHOO.example.container.dialog1);
    //    //SetDWH(450, 300, YAHOO.example.container.dialog1);
    //    YAHOO.example.container.dialog1.show();

    var pagetitle = "添加客户信息";
    parent._employeeTitle = pagetitle;
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=Cst_customer"));
    parent.NeedRefreshPage = this;
}

//-----------------------------------------
//编辑
//-----------------------------------------
var fnCustomEdit = function (key) {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    var pagetitle = "修改客户信息—" + record.getData("Cust_name"); ;
    parent._employeeTitle = pagetitle;
    //parent.addTabs(pagetitle, encodeURI("../../Extend/AutoLoadForm.aspx?r=" + Math.random() + "&entity=Cst_customer"));
    parent.addTabs(pagetitle, encodeURI("../Extend/Edit.aspx?r=" + Math.random() + "&entity=Cst_customer&id=" + record.getData(const_entityID)));
    parent.NeedRefreshPage = this;
}

//删除
var fnCustomDelete = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    if (confirm("确定删除这条记录？")) {
        var url = encodeURI("../../Crm/BSendSysNews.ashx?num=deleteV_Cst_customer&ID=" + record.getData(const_entityID) + "&r=" + Math.random());
        $.get(url, function (d, s) {
            if (d == 1) {
                alert("删除成功");
            } else {
                alert("删除失败");
            }
        });
    }
}

///给客户添加交往记录
var fnAddActivity = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }

    document.getElementById("dialog1_h").innerHTML = "给 " + record.getData("Cust_name") + " 添加交往记录";
    document.getElementById("EditUIWindow").src = "AutoLoadForm.aspx?r=" + Math.random() + "&entity=Cst_activity";
    //SetMaxDWH(YAHOO.example.container.dialog1);
    SetDWH(1111, 450, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}


///给客户添加联系人
var fnAddLinkman = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }

    document.getElementById("dialog1_h").innerHTML = "给 " + record.getData("Cust_name") + " 添加联系人";
    document.getElementById("EditUIWindow").src = "AutoLoadForm.aspx?r=" + Math.random() + "&entity=Cst_linkman";
    //SetMaxDWH(YAHOO.example.container.dialog1);
    SetDWH(1111, 450, YAHOO.example.container.dialog1);
    YAHOO.example.container.dialog1.show();
}

//单元格对象     XXX     XXX     单元格的值
var formatCust_Six = function (elCell, oRecord, oColumn, sData) {
    if (sData == "M") {
        elCell.innerHTML = "男";
    } else if (sData == "F") {
        elCell.innerHTML = "女";
    }
}

var formatCust_type = function (elCell, oRecord, oColumn, sData) {
    if (sData == "1") {
        elCell.innerHTML = "公司";
    } else if (sData == "2") {
        elCell.innerHTML = "个人";
    }
}